<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Nav/index')}">导航列表</a></li>
        <li><a href="{:url('Nav/add')}">添加导航</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="get" action="{:url('Nav/index')}">
        <input type="text" class="form-control" name="keyword" style="width: 200px;" value="{:input('request.keyword/s','')}" placeholder="请输入标题">
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('Nav/index')}">清空</a>
    </form>
    <form method="post" class="js-ajax-form margin-top-20" action="{:url('Nav/order')}">
        <div class="table-actions">
            <button class="btn btn-sm btn-primary js-ajax-submit" type="submit">排序</button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="16"><label><input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x"></label></th>
                <th width="50">排序</th>
                <th width="50">ID</th>
                <th>标题</th>
                <th>地址链接</th>
                <th>是否展示</th>
                <th width="120">操作</th>
            </tr>
            </thead>
            <tbody>
            <volist name="NavList" id="nav">
                <tr>
                    <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$nav.id}"></td>
                    <td><input name="list_orders[{$nav.id}]" class="input input-order mr5" type="text" style="width: 50px;" value="{$nav.list_order}"></td>
                    <td>{$nav.id}</td>
                    <td>{$nav.title}</td>
                    <td>{$nav.url}</td>
                    <td>
                        <eq name="$nav.switch" value="1">
                            <button type="button" class="btn btn-success toggle-switch" data-id="{$nav.id}">是</button>
                            <else/>
                            <button type="button" class="btn btn-danger toggle-switch" data-id="{$nav.id}">否</button>
                        </eq>
                    </td>
                    <td>
                        <a class="btn btn-xs btn-primary" href="{:url('Nav/edit', array('id' => $nav.id))}">编辑</a>
                        <a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('Nav/delete', array('id' => $nav.id))}">删除</a>
                    </td>
                </tr>
            </volist>
            </tbody>
        </table>
        <div class="pagination">
            {$page}
        </div>
    </form>
</div>
<script src="__STATIC__/js/admin.js?v={$_static_version}"></script>
<script>
    $(document).ready(function() {
        $('.toggle-switch').click(function() {
            var button = $(this);
            var id = button.data('id');
            $.post("{:url('Nav/toggleSwitch')}", {id: id}, function(data) {
                if (data.status === 1) {
                    if (data.switch === 1) {
                        button.removeClass('btn-danger').addClass('btn-success').text('是');
                    } else {
                        button.removeClass('btn-success').addClass('btn-danger').text('否');
                    }
                } else {
                    alert(data.msg);
                }
            }, 'json');
        });
    });
</script>
</body>
</html>
